from dataclasses import dataclass, field
import json
import os
from pathlib import Path
from dotenv import load_dotenv
from nicegui import app
from sqlmodel import create_engine, Session


######导航栏相关配置#######
@dataclass
class Section:
    """
    定义网页数据类型
    """

    section_name: str  # 网页名
    uri: str  # 网页地址


@dataclass
class LeftNav:
    """
    定义左侧边栏数据类型
    """

    expander_name: str  # expander_name，如果不需要expander，则设置为None
    section_name: str  # 网页名
    uri: str  # 网页地址


# 实例化网页，指明网页名、地址
sections = [
    Section("首页", "/"),
    Section("管理后台", "/admin"),
]
########################

#######基本配置(不用修改)###########
ROOT = Path(__file__).parent
app.add_static_files("/assets", ROOT / "assets")
unrestricted_page_routes = {"/", "/login", "/register"}

#########################
# other

# 移除以下行（46-76行）:
# ######数据库相关配置#####
# # MySQL连接配置
# load_dotenv("./.env")
# MYSQL_USER = os.getenv("MYSQL_USER", "root")
# MYSQL_PASSWORD = os.getenv("MYSQL_PASSWORD", "hdtx2022")
# MYSQL_HOST = os.getenv("MYSQL_HOST", "127.0.0.1")  # 或你的MySQL服务器地址
# MYSQL_PORT = int(os.getenv("MYSQL_PORT", "3306"))  # 默认MySQL端口
# MYSQL_DBNAME = os.getenv("MYSQL_DBNAME", "base_station")
# # SQLALCHEMY_DB_URI = "sqlite:///./db2.db"
# SQLALCHEMY_DB_URI = f"mysql+pymysql://{MYSQL_USER}:{MYSQL_PASSWORD}@{MYSQL_HOST}:{MYSQL_PORT}/{MYSQL_DBNAME}"
#
# # 创建引擎
# engine = create_engine(
#     SQLALCHEMY_DB_URI,
#     pool_size=5,  # 连接池大小
#     max_overflow=10,  # 超出连接池大小后可打开的连接数
#     pool_timeout=30,  # 获取连接的超时时间(秒)
#     pool_recycle=3600,  # 连接回收时间(秒)
#     echo=True,  # 显示SQL语句(调试用)
# )
#
#
# # Dependency,依赖注入 - 获取数据库会话
# def get_db():
#     db = Session(engine)
#     try:
#         yield db
#     finally:
#         db.close()
